import type { FieldConfig } from '@/components/TableFilter.vue'
import { getFormFields } from '@/utils/formUtils'
import type { FormFieldConfig } from '@/types/form'

// 表格列配置
export const tableColumns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '規則名稱',
    dataIndex: 'name',
  },
  {
    title: '員工類型',
    dataIndex: 'staffType',
  },
  {
    title: '駐診形式',
    dataIndex: 'shiftType',
  },
  {
    title: '全部醫師',
    dataIndex: 'allDoctor',
  },
  {
    title: '規則類型',
    dataIndex: 'ruleType',
  },
  {
    title: '銷售額不計診金',
    dataIndex: 'salesNoConsult',
  },
  {
    title: '開始日期',
    dataIndex: 'validFrom',
  },
  {
    title: '結束日期',
    dataIndex: 'validTo',
  },
  {
    title: '修改人',
    dataIndex: 'updatedBy',
  },
  {
    title: '修改時間',
    dataIndex: 'updatedAt',
  },
  {
    title: '操作',
    key: 'action',
    align: 'center',
  },
]
// 過濾項配置
export const filterFields: FieldConfig[] = [
  {
    name: 'name',
    label: '規則名稱',
    type: 'input',
    placeholder: '請輸入規則名稱',
  },
  {
    name: 'shift_type',
    label: '駐診形式',
    type: 'select',
    placeholder: '請選擇駐診形式',
    options: [
      { value: '', label: '全部' },
      { value: 1, label: '全日' },
      { value: 2, label: '半日' },
    ],
  },
  {
    name: 'staff_type',
    label: '員工類型',
    type: 'select',
    placeholder: '請選擇員工類型',
    options: [
      { value: '', label: '全部' },
      { value: 1, label: '合作醫師' },
      { value: 2, label: '員工醫師' },
    ],
  },
]

// 表單字段配置
const FormField: Record<string, FormFieldConfig> = {
  name: {
    label: '規則名稱',
    type: 'input',
    placeholder: '請輸入規則名稱',
    rules: [{ required: true, message: '請輸入規則名稱' }],
  },
  shiftType: {
    label: '駐診形式',
    type: 'radio',
    options: [
      { key: 1, label: '全日' },
      { key: 2, label: '半日' },
    ],
    defaultValue: 1,
  },
  staffType: {
    label: '員工類型',
    type: 'radio',
    options: [
      { key: 2, label: '員工醫師' },
      { key: 1, label: '合作醫師' },
    ],
    defaultValue: 2,
  },
  ruleType: {
    label: '規則類型',
    type: 'radio',
    options: [
      { key: 1, label: '跳級' },
      { key: 2, label: '累進' },
    ],
    defaultValue: 1,
  },
  allDoctor: {
    label: '全部醫師',
    type: 'radio',
    options: [
      { key: 1, label: '是' },
      { key: 0, label: '否' },
    ],
    defaultValue: 1,
  },
  salesNoConsult: {
    label: '銷售額不計診金',
    type: 'radio',
    tooltip: '銷售額不計診金',
    options: [
      { key: 0, label: '否' },
      { key: 1, label: '是' },
    ],
    defaultValue: 0,
  },
  validDate: {
    label: '生效時間',
    type: 'daterange',
    rules: [{ required: true, message: '請選擇有效日期' }],
  },
}

// 創建表單字段
export const getCreteFieldConfig = (fields?: string[]) => {
  return getFormFields(FormField, fields)
}

export const getEditFieldConfig = (fields?: string[]) => {
  return getFormFields(FormField, fields)
}
